package com.lzh.runke.entity;

import com.lzh.runke.enums.WaterPeriodEnum;
import com.lzh.runke.core.web_base.enums.BaseEnum;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * javaBean builder实现
 */
public class Coffee implements Serializable {

    private String name;
    private String brand;
    private LocalDateTime date;
    private WaterPeriodEnum waterPeriodEnum;


    public static Coffee.CoffeeBuilder builder() {
        return new Coffee.CoffeeBuilder();
    }

    public static class CoffeeBuilder {
        private String name;
        private String brand;
        private LocalDateTime date;
        private WaterPeriodEnum waterPeriodEnum;

        public CoffeeBuilder() {
        }

        public Coffee build() {
            return new Coffee(name, brand, date, waterPeriodEnum);
        }

        public Coffee.CoffeeBuilder name(final String name) {
            this.name = name;
            return this;
        }

        public Coffee.CoffeeBuilder brand(final String brand) {
            this.brand = brand;
            return this;
        }

        public Coffee.CoffeeBuilder date(final LocalDateTime date) {
            this.date = date;
            return this;
        }

        public Coffee.CoffeeBuilder waterPeriodEnum(final WaterPeriodEnum waterPeriodEnum) {
            this.waterPeriodEnum = waterPeriodEnum;
            return this;
        }

        /**
         * 设置水期枚举
         * 枚举值映射枚举对象
         *
         * @param value 水期value
         * @return WaterPeriodEnum
         */
        public Coffee.CoffeeBuilder waterPeriodEnum(String value) {
            boolean noValueMatching = Arrays.stream(WaterPeriodEnum.values()).noneMatch(a -> String.valueOf(a.getValue()).equals(value));
            if (noValueMatching) {
                this.waterPeriodEnum = null;
                return this;
            }
            this.waterPeriodEnum = BaseEnum.valueOf(Integer.valueOf(value), WaterPeriodEnum.class);
            return this;
        }

        @Override
        public String toString() {
            return "CoffeeBuilder{" +
                    "name='" + name + '\'' +
                    ", brand='" + brand + '\'' +
                    ", date=" + date +
                    '}';
        }
    }

    public Coffee() {
    }

    public Coffee(String name, String brand, LocalDateTime date, WaterPeriodEnum waterPeriodEnum) {
        this.name = name;
        this.brand = brand;
        this.date = date;
        this.waterPeriodEnum = waterPeriodEnum;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public LocalDateTime getDate() {
        return date;
    }

    public void setDate(LocalDateTime date) {
        this.date = date;
    }

    public WaterPeriodEnum getWaterPeriodEnum() {
        return waterPeriodEnum;
    }

    public void setWaterPeriodEnum(WaterPeriodEnum waterPeriodEnum) {
        this.waterPeriodEnum = waterPeriodEnum;
    }

    /**
     * 设置水期枚举
     * 枚举值映射枚举对象
     *
     * @param value 水期value
     * @return WaterPeriodEnum
     */
    public WaterPeriodEnum setWaterPeriodEnum(String value) {
        boolean noValueMatching = Arrays.stream(WaterPeriodEnum.values()).noneMatch(a -> String.valueOf(a.getValue()).equals(value));
        if (noValueMatching) {
            return null;
        }
        return BaseEnum.valueOf(Integer.valueOf(value), WaterPeriodEnum.class);
    }

    @Override
    public String toString() {
        return "Coffee{" +
                "name='" + name + '\'' +
                ", brand='" + brand + '\'' +
                ", date=" + date +
                '}';
    }
}

